package com.yjkf.zh.admin.service.impl;

import com.yjkf.zh.admin.dao.SysCollectMapper;
import com.yjkf.zh.admin.model.SysCollect;
import com.yjkf.zh.admin.service.SysCollectService;
import com.yjkf.zh.core.page.MybatisPageHelper;
import com.yjkf.zh.core.page.PageRequest;
import com.yjkf.zh.core.page.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Service
public class SysCollectServiceImpl implements SysCollectService {

    @Autowired
    private SysCollectMapper sysCollectMapper;

    @Override
    public PageResult findCollectName(PageRequest pageRequest, Long userId) {
        PageResult pageResult=null;
        Object collectName = pageRequest.getParam("collectName");
        Map<Object, Object> params = new HashMap<>();
        params.put("uid",userId);
        pageRequest.setParams(params);
        Object uid = pageRequest.getParam("uid");
        if(collectName==null||collectName.equals("")){
            pageResult = MybatisPageHelper.findPage(pageRequest, sysCollectMapper, "findPage", uid);
        }else{
            pageResult = MybatisPageHelper.findPage(pageRequest, sysCollectMapper, "findPageByName", collectName,uid);
        }
        return pageResult;
    }

    @Override
    public int save(SysCollect sysCollect,Long createId) {
            sysCollect.setCreateId(createId);
        return sysCollectMapper.saveCollects(sysCollect);
    }

    @Override
    public int delete(Long id) {
        return sysCollectMapper.delete(id);
    }
}
